package tp.pr4.instructions;

import tp.pr4.Interpreter;
import tp.pr4.Message;
import tp.pr4.NavigationModule;
import tp.pr4.RobotEngine;
import tp.pr4.instructions.exceptions.InstructionExecutionException;
import tp.pr4.instructions.exceptions.WrongInstructionFormatException;
import tp.pr4.items.ItemContainer;

/**
 * Shows the game help with all the instructions that the robot can execute.
 * This instruction works if the user writes HELP or AYUDA
 * 
 */
public class HelpInstruction implements Instruction {

	RobotEngine engine;
	@Override
	/**
	 * Parses the String returning a HelpInstruction instance or throwing a WrongInstructionFormatException()
	 * @param cad - Text String to parse
	 * @returns Instruction - Reference to an instance of HelpInstruction
	 * @throws WrongInstructionFormatException - When the String is not HELP
	 * 
	 */
	public Instruction parse(String cad) throws WrongInstructionFormatException {
		for (String i : Message.HELP_INSTRUCTION) {
			if (cad.equalsIgnoreCase(i))
				return new HelpInstruction();
		}
		throw new WrongInstructionFormatException(Message.NOT_UNDERSTAND);
	} // puede que haya que cambiar el mensaje de la excepcion

	@Override
	/**
	 * Help syntax
	 */
	public String getHelp() {
		String help = Message.HELP_INSTRUCTION[0];
		for (int i = 1; i < Message.HELP_INSTRUCTION.length; i++)
			help += "|" + Message.HELP_INSTRUCTION[i];

		return help;
	}

	@Override
	/**
	 * Configuration of the context for this instruction
	 */
	public void configureContext(RobotEngine engine,
			NavigationModule navigation, ItemContainer robotContainer) {
		this.engine = engine;

	}

	@Override
	/**
	 * Prints the help string of every instruction. It delegates to the Interpreter class.
	 */
	public void execute() throws InstructionExecutionException {
		engine.requestHelp();

	}

}
